<?php
class service_admin_http_web extends controller_prototype_class
{
	private $_serviceMapper;
	
    public function GetStatMapper()
    {
		if (!$this->_serviceMapper) 
		{
			include_once(_APP_PATH. "business/service/service_mapper.php");
			$this->_serviceMapper = ServiceMapper::GetInstance(); 
		}
		return $this->_serviceMapper;     	
    }	
	
    protected function ControllerInit ()
    {

    } 

    protected function PrimaryActionInit ($basicActionName)
    {  
        $this->GetModule()->GetDecorator()->SetMenuActiveElement('cfg/service');              
    }  
        
    /**
		экшен по-умолчанию
	*/
    public function PrAction ()
    {
        $this->outPr();
    }

    public function outPrAction ()
    {
        $t = $this->GetTemplator();
        $t->indexBlock = $this->OutIndexBlock();
        $t->cacheBlock = $this->OutCacheBlock();
        
        $this->Response()->SetBody($t->render('service/_out_all.phtml'));
    }    
    
    private function OutIndexBlock()
    {
        $t = $this->GetTemplator();
        //return $this->LoadTemplate ($t->render('service/_out_index_button.phtml'), 'Индексация');
    }

    private function OutCacheBlock()
    {
        $t = $this->GetTemplator();
        return $this->LoadTemplate ($t->render('service/_out_cache_buttons.phtml'), 'Очистка кэша');        
    }
    
    public function delete_html_cachePrAction()
    {      
        if (!$this->GetStatMapper()->DeleteHTMLCache()) 
        {     
            $this->Libs()->messanger->createMessage('Ошибка при очистке html кэша', MESSAGE_ERROR);
        }
        else 
        {
            $this->Libs()->messanger->createMessage('Кэш html удалён');            
        }
        
       	MozgRoute::Get('http')->Redirect(array('module' => 'admin', 'ctrl' => 'service'));                
    }    
    
    public function delete_css_cachePrAction()
    {     
        if (!$this->GetStatMapper()->DeleteCSSCache()) 
        {     
            $this->Libs()->messanger->createMessage('Ошибка при очистке кэша стилей', MESSAGE_ERROR);
        }
        else 
        {
            $style = SysLoader::GetModule('media', 'http', '_web')->GetCtrl('style');
            $style->UpdateStyleRevision('css'); 
                       
            $this->Libs()->messanger->createMessage('Кэш стилей удалён');            
        }
        
        MozgRoute::Get('http')->Redirect(array('module' => 'admin', 'ctrl' => 'service'));        
    }

    public function delete_js_cachePrAction()
    {      
        if (!$this->GetStatMapper()->DeleteJSCache()) 
        {                        
            $this->Libs()->messanger->createMessage('Ошибка при очистке javascript кэша', MESSAGE_ERROR);
        }
        else 
        {
            $style = SysLoader::GetModule('media', 'http', '_web')->GetCtrl('style');
            $style->UpdateStyleRevision('js');
                        
            $this->Libs()->messanger->createMessage('Кэш javascript удалён');            
        }        
        
        MozgRoute::Get('http')->Redirect(array('module' => 'admin', 'ctrl' => 'service'));
    }    

    public function delete_tmp_cachePrAction()
    {
        if (!$this->GetStatMapper()->DeleteTMPCache()) 
        {
            $this->Libs()->messanger->createMessage('Ошибка при очистке кэша шаблонов', MESSAGE_ERROR);
        }
        else 
        {
            $this->Libs()->messanger->createMessage('Кэш шаблонов удалён');            
        }        
        
        MozgRoute::Get('http')->Redirect(array('module' => 'admin', 'ctrl' => 'service'));
    }     
    
    protected function LoadTemplate ($content, $title)
    {
        $t = $this->GetTemplator();
        $t->title = $title;
        $t->content = $content;
        return $t->render('_main_block_template.phtml');
    }     
}